<template>
  <svg aria-hidden="true" class="svg-icon" :style="sizeStyle">
    <use :xlink:href="symbolId" :fill="color" />
  </svg>
</template>

<script>
import { defineComponent, computed } from 'vue'

export default defineComponent({
  name: 'SvgIcon',
  props: {
    // 前缀
    prefix: {
      type: String,
      default: 'icon'
    },
    size: {
      type: [String, Number]
    },
    name: String,
    color: {
      type: String,
      default: 'currentColor'
    }
  },
  setup (props) {
    const symbolId = computed(() => `#${props.prefix}-${props.name}`)

    const sizeStyle = computed(() => {
      let S = '1em'
      if (props.size) {
        S = `${props.size.replace('px', '')}px`
      }

      return { width: S, height: S }
    })

    return {
      symbolId,
      sizeStyle
    }
  }
})
</script>

<style lang="scss" scoped>
  .svg-icon {
    display: inline-block;
    overflow: hidden;
    // font-size: 0;
    // vertical-align: middle;
  }
</style>
